#pragma once
#include "HashTable.h"

namespace cl {
	template<class K, class V, class HashFunc = std::hash<K>>
	class unordered_map {
		struct MapKeyOfT {
			const K& operator()(const pair<K, V>& kv) { return kv.first; }
		};
	public:
		typedef typename open_hash::HashTable<K, pair<K, V>, MapKeyOfT, HashFunc>::iterator iterator;

		iterator begin() { return _ht.begin(); }
		iterator end() { return _ht.end(); }
		iterator find(const K& key) { return _ht.Find(key); }
		bool erase(const K& key) { return _ht.Erase(key); }
		pair<iterator, bool> insert(const pair<K, V>& kv) {
			return _ht.Insert(kv);
		}
		V& operator[](const K& key) {
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}

	private:
		open_hash::HashTable<K, pair<K, V>, MapKeyOfT, HashFunc> _ht;
	};
}